package main

import (
	"flag"
	"fmt"
	"github.com/zeromicro/go-zero/core/conf"
	"github.com/zeromicro/go-zero/rest"
	"go-zero-example/cmd/userapi/internal/config"
	"go-zero-example/cmd/userapi/internal/handler"
	"go-zero-example/cmd/userapi/internal/svc"
)

var configFile = flag.String("f", "./etc/demo-api.yaml", "the config file")

func main() {
	//// 数据库初始化连接
	//dir, err := os.Getwd()
	//if err != nil {
	//	panic(err)
	//}
	//path := dir + "/config.json"
	//// 实例化配置文件
	//_ = util2.ReadJson(path)
	//// 实例化数据库
	//_, err = util2.GetOrmEngine()
	//if err != nil {
	//	panic(err)
	//}
	// go-zero ctl 生成的代码
	flag.Parse()

	var c config.Config
	conf.MustLoad(*configFile, &c)
	// 直连模式
	c.UserRpcConf.Target = "0.0.0.0:8080"
	//c.UserRpcConf.Etcd
	server := rest.MustNewServer(c.RestConf)

	defer server.Stop()

	ctx := svc.NewServiceContext(c)
	handler.RegisterHandlers(server, ctx)

	fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
	server.Start()
}
